package com.yi.wood.web.service.impl;

import com.yi.wood.entity.AppUserAddress;
import com.yi.wood.service.impl.AbstractAppUserAddressService;
import com.yi.wood.web.service.AppUserAddressProService;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Sort;
import org.springframework.data.repository.query.QueryByExampleExecutor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author MoYi
 * create date 2019/4/14 18:02
 */
@Service("appUserAddressProService")
public class AppUserAddressProServiceImpl extends AbstractAppUserAddressService implements AppUserAddressProService {



    @Override
    public List<AppUserAddress> findAddressByUserId(Long userId) {

//        ExampleMatcher matcher = ExampleMatcher.matching()
//                .withMatcher("username", ExampleMatcher.GenericPropertyMatchers.startsWith())//模糊查询匹配开头，即{username}%
//                .withMatcher("address" ,ExampleMatcher.GenericPropertyMatchers.contains())//全部模糊查询，即%{address}%
//                .withIgnorePaths("password");//忽略字段，即不管password是什么值都不加入查询条件

        Sort sort = Sort.by(Sort.Direction.DESC,"type");
        AppUserAddress appUserAddress = new AppUserAddress();
        appUserAddress.setUserId(userId);
        Example<AppUserAddress> addressExample = Example.of(appUserAddress);
        return appUserAddressDao.findAll(addressExample, sort);
    }
}
